<?php

include(dirname(__FILE__). '/../../bootstrap/Doctrine.php');

$t = new lime_test(3);

$t->comment('->getCompanySlug()');
$job = Doctrine_Core::getTable('JobeetJob')->createQuery()->fetchOne();
$t->is($job->getCompanySlug(), Jobeet::slugify($job->getCompany()), '->getCompanySlug() devuelve el slug para la compañia');

$t->comment('->save()');

$job = create_job();
$job->save();
$expiresAt = date('Y-m-d', time() + 86400 * sfConfig::get('app_active_days'));
$t->is($job->getDateTimeObject('expires_at')->format('Y-m-d'), $expiresAt, '->save() actializa expires_at si no seteado');


$job = create_job(array('expires_at' => '2012-09-23'));
$job->save();
$t->is($job->getDateTimeObject('expires_at')->format('Y-m-d'), '2012-09-23', '->save() no actializa expirest-at si ya fue seteado');

function create_job($defauls = array()) {
    
    static $category = null;
    
    if(is_null($category)) {
        
        $category = Doctrine_core::getTable('JobeetCategory')
                ->createQuery()
                ->limit(1)
                ->fetchOne();
    }
    
    $job = new JobeetJob();
    $job->fromArray(array_merge(array(
        'category_id'   => $category->getId(),
        'company'       => 'Sensio Labs',
        'position'      => 'Sensio Tester',
        'location'      => 'Paris, France',
        'description'   => 'Testing is fun',
        'how_to_apply'  => 'Send e-Mail',
        'email'         => 'job@example.com',
        'token'         => rand(1111, 9999),
        'is_activated'  => true,
    ), $defauls)); 
    
    return $job;
}


?>